package com.nguc.ngucpractice.service.impl;

import com.nguc.ngucpractice.common.entity.Result;
import com.nguc.ngucpractice.dao.CategoryDao;
import com.nguc.ngucpractice.pojo.Category;
import com.nguc.ngucpractice.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * User:曹帅
 * Date:2020/8/2
 * Version:1.0
 */
@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryDao categoryDao;

    @Override
    public Result findCategoryById(Integer categoryId) {
        Result result = new Result();
        Category category = categoryDao.selectByPrimaryKey(categoryId);
        result.setStatus("0");
        result.setData(category);
        return result;
    }

    @Override
    public Result findListByParentId(Integer parentId) {
        Result result = new Result();
        parentId = !StringUtils.isEmpty(parentId) ? parentId : 0;
        List<Category> categoryList = categoryDao.findCategoryListByParentId(parentId);
        result.setStatus("0");
        result.setData(categoryList);
        return result;
    }
}
